package thread;

import cn.hutool.core.util.RandomUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * @Author: 582895699@qq.com
 * @Desctription: CountDownLatch-Runnable
 * @Date: Created in 2021/12/13 16:19
 */
@Slf4j
public class TestCallAbleClass implements Runnable {
    private CountDownLatch countDownLatch;

    public TestCallAbleClass(CountDownLatch countDownLatch) {
        this.countDownLatch = countDownLatch;
    }

    @Override
    public void run() {
        Thread thread = Thread.currentThread();
        int randomInt = RandomUtil.randomInt(1, 5);
        log.info("thread:[{}];randomInt:[{}]", thread.getName(), randomInt);
        try {
            TimeUnit.SECONDS.sleep(randomInt);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        countDownLatch.countDown();
    }
}
